// packageAPI/pages/Interface/Interaction/Interaction.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    schema: [
      {
        label:'标题：',
        prop:'title',
        type:'text',
        numRang: null
      },
      {
        label:'提示内容：',
        prop:'content',
        type:'text',
        numRang: null
      },
      {
        label:'取消按钮：',
        prop:'showCancel',
        type:'picker',
        labelOptions:['是','否'],
        valueOptions:[true, false]
      },
      {
        label:'取消按钮文字：',
        prop:'cancelText',
        type:'text',
        numRang: null
      },
      {
        label:'确定按钮文字：',
        prop:'confirmText',
        type:'text',
        numRang: null
      },
      {
        label:'是否显示输入框：',
        prop:'editable',
        type:'picker',
        labelOptions:['是','否'],
        valueOptions:[true, false]
      },
      {
        label:'提示文本：',
        prop:'placeholderText',
        type:'text',
        numRang: null
      },
    ],
    title: '',
    result: '',
    options: {
      title: '提示',
        content: '我是modal',
        showCancel: true,
        cancelText: '取消',
        confirmText: '确定',
        editable: false,
        placeholderText: ''
    },
    apiType: '',
    remark: '',
    webUrl: '',
    showModelOptions: [
      {
        label:'标题：',
        prop:'title',
        type:'text',
        numRang: null
      },
      {
        label:'提示内容：',
        prop:'content',
        type:'text',
        numRang: null
      },
      {
        label:'取消按钮：',
        prop:'showCancel',
        type:'picker',
        labelOptions:['是','否'],
        valueOptions:[true, false]
      },
      {
        label:'取消按钮文字：',
        prop:'cancelText',
        type:'text',
        numRang: null
      },
      {
        label:'确定按钮文字：',
        prop:'confirmText',
        type:'text',
        numRang: null
      },
      {
        label:'是否显示输入框：',
        prop:'editable',
        type:'picker',
        labelOptions:['是','否'],
        valueOptions:[true, false]
      },
      {
        label:'提示文本：',
        prop:'placeholderText',
        type:'text',
        numRang: null
      },
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log('options', options)
    let aJson = {
      apiType: options.zh,
      title: options.title,
      zh:options.zh,
      remark: options.remark,
      webUrl: options.webUrl
    }
    if (options.zh == 'wx.showModal') {
      aJson['schema'] = this.data.showModelOptions;
      aJson['options'] = {
        title: '提示',
        content: '我是modal',
        showCancel: true,
        cancelText: '取消',
        confirmText: '确定',
        editable: false,
        placeholderText: ''
      }
    }else if(options.zh == 'wx.showLoading'||options.zh == 'wx.hideLoading'){
      this.setData({
        schema:[
          {
            label:'提示内容',
            prop:'title',
            type:'text',
            numRang: null
          },
          {
            label:'透明蒙层',
            prop:'mask',
            type:'picker',
            labelOptions:['是','否'],
            valueOptions:[true, false]
          }
        ],
        options:{
          title:'我是提示内容',
          mask:true
        }
      })
    }else if(options.zh=='wx.showToast'||options.zh=='wx.hideToast'){
      this.setData({
        schema:[
          {
            label:'提示内容',
            prop:'title',
            type:'text',
            numRang: null
          },
          {
            label:'图标',
            prop:'icon',
            type:'picker',
            labelOptions:['成功','失败','加载','不显示'],
            valueOptions:['success', 'error','loading','none']
          },
          {
            label:'延迟时间',
            prop:'duration',
            type:'number',
            labelOptions:[],
            valueOptions:[]
          },
          {
            label:'自定义图标',
            prop:'image',
            type:'picker',
            labelOptions:['系统默认','图1','图2','图3'],
            valueOptions:['',"../img/feedback.png", "../img/framework.png","../img/network.png"]
          },{
            label:'透明蒙层',
            prop:'mask',
            type:'picker',
            labelOptions:['是','否'],
            valueOptions:[true, false]
          },
        ],
        options:{
          title:'我是Toast提示',
          mask:true,
          icon:'success',
          image:'',
          duration:5000
        }
      })
    }else if(options.zh==='wx.showActionSheet'){
      this.setData({
        schema:[
          {
            label:'按钮数组',
            prop:'itemList',
            type:'picker',
            labelOptions:["3个item['A','B','C']","4个item['A','B','C','D']","5个item['A','B','C','D','E']",],
            valueOptions:[3,4,5]
          },{
            label:'警示文案',
            prop:'alertText',
            type:'text'
          },{
            label:'文字颜色',
            prop:'itemColor',
            type:'picker',
            labelOptions:['红','黄','黑','绿'],
            valueOptions:["#ff0000", 'yellow','black','green']
          }
          
        ],
        options:{
          itemList:3,
          alertText:'',
          itemColor:'black'
        }
      })
    }else if(options.zh==='wx.enableAlertBeforeUnload'){
      this.setData({
        schema:[
          {
            label:'内容',
            prop:'message',
            type:'text'
          }
        ],
        options:{
          message:'这里是询问对话框内容'
        }
      })
    }

    wx.setNavigationBarTitle({
      title: options.title,
    })

    this.setData({
      apiType: aJson.zh,
      title: aJson.title,
      zh: aJson.zh,
      remark: aJson.remark,
      webUrl: aJson.webUrl,
      // schema: aJson.schema,
      // options: aJson.options
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  showLoadingFunc(){
    const that = this
    wx.showLoading({
      title: that.data.options.title,
      mask:that.data.options.mask,
      success:(res)=>{
        that.setData({
          result: res
        })
      },
      fail:(err)=>{
        that.setData({
          result: err
        })
      }
    })

    const st = setTimeout(()=>{
      wx.hideLoading({
        noConflict:false,
        success:(res)=>{
          that.setData({
            result: res
          })
        },fail(error) {
          that.setData({
            result: error
          })
        },
        complete(result) {
          that.setData({
            result: result
          })
        }
      })
      clearTimeout(st)
    },3000)
  },
  showActionSheetFunc(){
    const that = this
    let parm = that.data.options
    switch (parm.itemList) {
      case 3:
        parm.itemList = ['A','B','C']
        break;
      case 4:
        parm.itemList = ['A','B','C','D']
          break;
      case 5:
        parm.itemList = ['A','B','C','D','E']
            break;
      default:
        break;
    }
    wx.showActionSheet({
      ...parm,
      success(res) {
        that.setData({
          result: res
        })
      },
      fail(error) {
        that.setData({
          result: error
        })
      },
      complete(result) {
        that.setData({
          result: result
        })
      }
    })
  },
  showToastFunc() {
    let that = this;
    wx.showToast({
      ...that.data.options,
      success(res) {
        that.setData({
          result: res
        })
      },
      fail(error) {
        that.setData({
          result: error
        })
      },
      complete(result) {
        that.setData({
          result: result
        })
      }
    })
    const st = setTimeout(()=>{
      wx.hideToast({
        success(res) {
          that.setData({
            result: res
          })
        },
        fail(error) {
          that.setData({
            result: error
          })
        },
        complete(result) {
          that.setData({
            result: result
          })
        }
      })
      clearTimeout(st)
    },2000)
  },
  back(){
    let that = this;
    wx.enableAlertBeforeUnload({
      ...that.data.options,
      success(res) {
        that.setData({
          result: res
        })
      },
      fail(error) {
        that.setData({
          result: error
        })
      },
      complete(result) {
        that.setData({
          result: result
        })
      }
    })
  },
  setOptons(e) {
    console.log('获取设置的值', e.detail.formData)
    this.setData({
      options: e.detail.formData
    })
  },
  showModalFunc() {
    let that = this;
    wx.showModal({
      title: that.data.options.title,
      content: that.data.options.content,
      showCancel: that.data.options.showCancel,
      cancelText: that.data.options.cancelText,
      cancelColor: '#000000',
      confirmText: that.data.options.confirmText,
      confirmColor: '#576B95',
      editable: that.data.options.editable,
      placeholderText: that.data.options.placeholderText,
      success(res) {
        console.log('设置成功', res)
        that.setData({
          result: res
        })
      },
      fail(error) {
        console.log('设置失败', error)
        that.setData({
          result: error
        })
      },
      complete(result) {
        console.log('设置成功或失败继续', result)
        that.setData({
          result: result
        })
      }
    })
  },
  getWindowInfoFunc() {
    const windowInfo = wx.getWindowInfo()
    console.log('windowInfo', windowInfo)
    this.setData({
      result: windowInfo
    })
  },
  getSystemSettingFunc() {
    const systemInfo = wx.getSystemSetting()
    console.log('systemInfo', systemInfo)
    this.setData({
      result: systemInfo
    })
  },
  getSystemInfoSyncFunc() {
    const systemInfo = wx.getSystemInfoSync();
    console.log('systemInfo', systemInfo)
    this.setData({
      result: systemInfo
    })
  },
  getSystemInfoAsyncFunc() {
    let that = this;
    wx.getSystemInfoAsync({
      success (res) {
        that.setData({
          result: res
        })
      },
      fail(error) {
        console.log('设置失败', error)
        that.setData({
          result: error
        })
      },
      complete(result) {
        console.log('设置成功或失败继续', result)
        that.setData({
          result: result
        })
      }
    })
  },
  getSystemInfoFunc() {
    let that = this;
    wx.getSystemInfo({
      success (res) {
        that.setData({
          result: res
        })
      },
      fail(error) {
        console.log('设置失败', error)
        that.setData({
          result: error
        })
      },
      complete(result) {
        console.log('设置成功或失败继续', result)
        that.setData({
          result: result
        })
      }
    })
  },
  getSkylineInfoSyncFunc() {
    const data = wx.getSkylineInfoSync();
    this.setData({
      result: data
    })
  },
})